package com.example.springaidemo.controller;

import com.example.springaidemo.model.ChatSession;
import com.example.springaidemo.service.AiService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class AiController {

    private final AiService aiService;

    @Autowired
    public AiController(AiService aiService) {
        this.aiService = aiService;
    }

    // 使用DeepSeek的端点
    @GetMapping("/generate/deepseek")
    public String generateWithDeepSeek(@RequestParam String prompt) {
        return aiService.generateContentWithDeepSeek(prompt);
    }

    @GetMapping("/chat/deepseek")
    public String chatWithDeepSeek(@RequestParam String message) {
        return aiService.chatWithDeepSeek(message);
    }

    // 使用百炼的端点
    @GetMapping("/generate/bailian")
    public String generateWithBailian(@RequestParam String prompt) {
        return aiService.generateContentWithBailian(prompt);
    }

    @GetMapping("/chat/bailian")
    public String chatWithBailian(@RequestParam String message) {
        System.out.println("message: " + message);
        return aiService.chatWithBailian(message);
    }

    // 兼容原有API的端点，现在默认使用DeepSeek
    @GetMapping("/generate")
    public String generate(@RequestParam String prompt) {
        return aiService.generate(prompt);
    }

    @GetMapping("/chat")
    public String chat(@RequestParam String message) {
        return aiService.chat(message);
    }
    
    // 多轮对话相关端点
    
    // 创建新会话
    @GetMapping("/chat/session/create")
    public ChatSession createChatSession() {
        return aiService.createNewSession();
    }
    
    // 使用DeepSeek进行多轮对话
    @GetMapping("/chat/deepseek/history")
    public String chatWithDeepSeekHistory(
            @RequestParam String sessionId,
            @RequestParam String message) {
        return aiService.chatWithDeepSeekHistory(sessionId, message);
    }
    
    // 使用百炼进行多轮对话
    @GetMapping("/chat/bailian/history")
    public String chatWithBailianHistory(
            @RequestParam String sessionId,
            @RequestParam String message) {
        return aiService.chatWithBailianHistory(sessionId, message);
    }
    
    // 默认的多轮对话端点
    @GetMapping("/chat/history")
    public String chatWithHistory(
            @RequestParam String sessionId,
            @RequestParam String message) {
        return aiService.chatWithHistory(sessionId, message);
    }
}